home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / makeml < prev   
Encoding:
Text File  |  1993-02-08  |  12.4 KB  |  686 lines

  1. #!/bin/sh
  2. #
  3. # makeml - build the SML/NJ system
  4. #
  5. #set -x
  6.  
  7. CMD="$0>"
  8.  
  9. CSV=""
  10. CALLEESAVE=""
  11. MESSAGE='""'
  12. MACHINE=""
  13. OPSYS="BSD"
  14. ENDIAN=""
  15. DEBUG=""
  16. IMAGE=""
  17. MODULEKIND="Int"
  18. TARGET=""
  19. SHARE="TRUE"
  20. DEFS=""
  21. PRECLEAN="TRUE"
  22. POSTCLEAN=""
  23. MKRUN="TRUE"
  24. RUNTIME="runtime"
  25. NOBOOT=""
  26. AS="as"
  27. COMMAND=""
  28. IONLY=""
  29. CFL=""
  30. LDFLAGS=""
  31. MOFILES=""
  32. USE_GCC=""
  33. SHELL="/bin/sh"
  34. LIBS=""
  35. MP_SYSTEM=""
  36. HPUX_VERSION="0"
  37.  
  38. #
  39. # gc params
  40. #
  41. HEAP=5120
  42. RATIO=5
  43. SOFTLIMIT=12288
  44.  
  45. #
  46. # try to guess the machine type
  47. #
  48. if [ -f /bin/arch ]; then
  49.     case `/bin/arch` in
  50.     sun3)
  51.         set - -sun3 sunos $*
  52.     ;;
  53.     sun4)
  54.         set - -sun4 sunos $*
  55.     ;;
  56.     esac
  57. elif [ -f /hp-ux ]; then
  58.     set -- -m68 hpux $*
  59. elif [ -d /mac ]; then
  60.       set - -m68 aux $*
  61. fi
  62.  
  63. #
  64. # process command-line options
  65. #
  66. while test "$#" != "0"
  67. do
  68.     arg=$1
  69.     shift
  70.     case $arg in
  71.       #
  72.       # Options to specify machines/os configuration
  73.       #
  74.     -rs6k|-rs6000)
  75.         MACHINE=RS6000
  76.         case $1 in
  77.         aix) OPSYS=AIX
  78.              DEFS="$DEFS -DBSD -D_BSD"
  79.              LDFLAGS="$LDFLAGS -lbsd -bnso -bI:/lib/syscalls.exp"
  80.              ;;
  81.         *)
  82.             echo "$CMD opsys must be aix" 
  83.             exit 1
  84.         ;;
  85.             esac
  86.         shift
  87.         ;;
  88.     -sun3|-sun4)
  89.         case $arg in
  90.         -sun3) MACHINE=M68;;
  91.         -sun4) MACHINE=SPARC;;
  92.         esac
  93.         case $1 in
  94.         mach)  OPSYS=MACH; DEFS="$DEFS -DBSD" ;;
  95.         sunos) OPSYS=SUNOS ;;
  96.         *)
  97.             echo "$CMD must specify opsys arg for SUN (sunos or mach)"
  98.             exit 1
  99.         ;;
  100.         esac
  101.         shift
  102.     ;;
  103.     -next|-NeXT)
  104.         MACHINE=M68;
  105.         OPSYS=NeXT
  106.         case $1 in
  107.         2|2.0|2.1) ;;
  108.         3|3.0)
  109.             DEFS="$DEFS -DNeXT_3_0"
  110.         ;;
  111.         *)
  112.             echo "$CMD must specify opsys version for NeXT (2.0, 3.0)"
  113.             exit 1
  114.         ;;
  115.         esac
  116.         shift
  117.     ;;
  118.     -decstation|-DECstation)  # DEC mips box
  119.         MACHINE=MIPS
  120.         ENDIAN=Little
  121.         case $1 in
  122.         ultrix|bsd) OPSYS=BSD ;;
  123.         mach)       OPSYS=MACH; DEFS="$DEFS -DBSD";;
  124.         *)
  125.             echo "$CMD must specify opsys arg for DECstation (ultrix or mach)"
  126.             exit 1
  127.         ;;
  128.         esac
  129.         shift
  130.     ;;
  131.     -vax)
  132.         MACHINE=VAX
  133.         case $1 in
  134.         bsd)    OPSYS=BSD ;;
  135.         mach)   OPSYS=MACH; DEFS="$DEFS -DBSD";;
  136.         *)
  137.             echo "$CMD must specify opsys arg for VAX (bsd or mach)"
  138.             exit 1
  139.         ;;
  140.         esac
  141.         shift
  142.     ;;
  143.         -sgi)   # Silicon Graphics box with MIPS chip
  144.         MACHINE=MIPS
  145.         ENDIAN=Big
  146.         OPSYS=SGI
  147.         case $1 in
  148.         irix3) DEFS="$DEFS -D_BSD_SIGNALS" ;;
  149.         irix) DEFS="$DEFS -D_BSD_SIGNALS -cckr -Dsgi" ;;
  150.         *)
  151.             echo "$CMD must specify opsys arg for SGI (irix or irix3)"
  152.             exit 1
  153.         ;;
  154.         esac
  155.         shift
  156.     ;;    
  157.     -mips)  # MipsCo box
  158.         MACHINE=MIPS
  159.         ENDIAN=Big
  160.         case $1 in
  161.         riscos) OPSYS=RISCos; CFL="$CFL -systype bsd43" ;;
  162.          news)   OPSYS=BSD;;
  163.         mach)   OPSYS=MACH; DEFS="$DEFS -DBSD" ;;
  164.         *)
  165.             echo "$CMD must specify opsys arg for MIPS (riscos, mach or news)"
  166.             exit 1
  167.         ;;
  168.         esac
  169.         shift
  170.     ;;
  171.     -hppa)
  172.         MACHINE=HPPA
  173.         SHARE=""
  174.         MESSAGE='("Beta release version"^chr(10))'
  175.         case $1 in
  176.         hpux) OPSYS=HPUX ;;
  177.         hpux8) OPSYS=HPUX; HPUX_VERSION="8" ;;
  178.         mach) OPSYS=MACH ;;
  179.         *)
  180.             echo "$CMD must specify opsys arg for hppa (hpux, hpux8 or mach)"
  181.             exit 1
  182.         ;;
  183.         esac
  184.         shift
  185.     ;;
  186.     -m68)
  187.         MACHINE=M68
  188.         case $1 in
  189.         sunos)  OPSYS=SUNOS ;;
  190.         hpux) OPSYS=HPUX ;;
  191.         hpux8) OPSYS=HPUX; HPUX_VERSION="8" ;;
  192.                 aux) OPSYS=AUX; AS="gas"; USE_GCC="TRUE"; CFL="$CFL -static" ;;
  193.         mach) OPSYS=MACH ;;
  194.         more) OPSYS=MORE ;;
  195.         *)
  196.             echo "$CMD must specify opsys arg for M68 (sunos, hpux, hpux8, more or aux)"
  197.             exit 1
  198.         ;;
  199.         esac
  200.         shift
  201.     ;;
  202.     -i386|-386|-i486|-486)
  203.         MACHINE=I386
  204.         case $1 in
  205.         bsd)    OPSYS=BSD ;;
  206.         bsd386) OPSYS=BSD; DEFS="$DEFS -DBSD386";;
  207.         mach)   OPSYS=MACH; DEFS="$DEFS -DBSD";;
  208.         *)
  209.             echo "$CMD must specify opsys arg for i386/i486 (bsd, bsd386 or mach)"
  210.             exit 1
  211.         ;;
  212.         esac
  213.         shift
  214.     ;;
  215.         -sequent)   # sequent symmetry 
  216.         MACHINE=I386
  217.             case $1 in
  218.                 dynix3)    OPSYS=DYNIX; DEFS="$DEFS -DBSD";;
  219.         *)
  220.             echo "$CMD opsys must be dynix3" 
  221.             exit 1
  222.                ;;
  223.             esac
  224.             shift
  225.          ;;
  226.       #
  227.       # options to select kind of system to build (batch, debug, ...)
  228.       #
  229.     -batch)
  230.         MODULEKIND=Comp
  231.     ;;
  232.     -target)
  233.         if test "$#" = "0"
  234.         then
  235.         echo "$CMD must supply machine for -target option"
  236.         exit 1
  237.         fi
  238.         MODULEKIND=Comp
  239.         TARGET=$1
  240.         shift
  241.     ;;
  242.     -debug)
  243.         DEBUG="D"
  244.         COMMAND=$COMMAND'System.Control.CG.rounds:=1;use "dbguser/load.sml";'
  245.     ;;
  246.     -debug0)
  247.         DEBUG="D"
  248.         COMMAND=$COMMAND'System.Control.CG.rounds:=1;'
  249.     ;;
  250.     -i)
  251.         COMMAND=$COMMAND"System.Control.interp := true;"
  252.     ;;
  253.     -ionly)
  254.         COMMAND=$COMMAND"System.Control.interp := true;"
  255.         IONLY="TRUE"
  256.     ;;
  257.       #
  258.       # other options
  259.       #
  260.         -g)
  261.         CFL="$CFL -g"
  262.     ;;
  263.     -gcc)
  264.         USE_GCC="TRUE"
  265.     ;;
  266.     -noshare)
  267.         SHARE=""
  268.     ;;
  269.     -pervshare)
  270.         MOFILES="Perv.mos"
  271.     ;;
  272.     -run)
  273.         MKRUN="TRUE"
  274.         NOBOOT="TRUE"
  275.     ;;
  276.     -norun)
  277.         MKRUN=""
  278.         PRECLEAN=""
  279.     ;;
  280.         -callee)
  281.         CALLEESAVE="$1"
  282.             DEFS="$DEFS -DCALLEESAVE=$CALLEESAVE"
  283.         
  284.         shift
  285.     ;;
  286.     -mp)
  287.         if test "$#" = "0"
  288.         then
  289.         echo "$CMD must supply number of processors for -mp option"
  290.          exit 1
  291.         fi
  292.         MP_SYSTEM="TRUE"
  293.         DEFS="$DEFS -DMAX_PROCS=$1"
  294.         shift
  295.     ;;
  296.     -noclean)
  297.         PRECLEAN=""
  298.     ;;
  299.     -cleanup)
  300.         POSTCLEAN="TRUE"
  301.     ;;
  302.     -o)
  303.         if test "$#" = "0"
  304.         then
  305.         echo "$CMD must supply image name for -o option"
  306.         exit 1
  307.         fi
  308.         IMAGE=$1
  309.         shift
  310.     ;;
  311.     -runtime)
  312.         if test "$#" = "0"
  313.         then
  314.         echo "$CMD must supply runtime directory for -runtime option"
  315.         exit 1
  316.         fi
  317.         RUNTIME=$1
  318.         shift
  319.     ;;
  320.     -mo)
  321.         if test "$#" = "0"
  322.         then
  323.         echo "$CMD must supply mo directory for -mo option"
  324.         exit 1
  325.         fi
  326.         MO=$1
  327.         shift
  328.     ;;
  329.     -h)
  330.         if test "$#" = "0"
  331.         then
  332.         echo "$CMD must supply argument for -h option"
  333.         exit 1
  334.         fi
  335.         HEAP=$1
  336.         shift
  337.     ;;
  338.     -r)
  339.         if test "$#" = "0"
  340.         then
  341.         echo "$CMD must supply argument for -r option"
  342.         exit 1
  343.         fi
  344.         RATIO=$1
  345.         shift
  346.     ;;
  347.     -m)
  348.         if test "$#" = "0"
  349.         then
  350.         echo "$CMD must supply argument for -m option"
  351.         exit 1
  352.         fi
  353.         SOFTLIMIT=$1
  354.         shift
  355.     ;;
  356.     -D*)
  357.         DEFS="$DEFS $arg"
  358.     ;;
  359.     *)
  360.         echo "$CMD unrecognized option $arg"
  361.         exit 1
  362.     ;;
  363.     esac
  364. done
  365.  
  366. if test -n "$MP_SYSTEM"
  367. then
  368.     MESSAGE='("(with multi-processor support)"^chr(10))'
  369.     if test "$OPSYS" = SGI
  370.     then
  371.     LIBS="$LIBS -lmpc"
  372.     else
  373.     echo "$CMD machine and/or OS do(es) not support more than 1 processor"
  374.     exit 1
  375.     fi
  376. fi
  377.  
  378. #
  379. # HPPA cannot execute in sharable mode. -noshare is default.
  380. #
  381. if test "$MACHINE" = HPPA
  382. then
  383.     if test -n "$MOFILES"
  384.     then
  385.       echo "$CMD Hppa cannot be built using -pervshare"
  386.       echo "$CMD ignoring -pervshare ..."
  387.       MOFILES=""
  388.     fi
  389. fi
  390.  
  391.  
  392. if test -z "$IMAGE"
  393. then
  394.     if test "$MODULEKIND" = Int
  395.     then
  396.     if test -n "$IONLY"
  397.     then
  398.         IMAGE=smli
  399.     else
  400.         IMAGE=sml
  401.     fi
  402.     if test -n "$DEBUG"
  403.     then IMAGE="$IMAGE"d
  404.     fi
  405.     else
  406.     IMAGE=smlc
  407.     fi
  408. fi
  409.  
  410. if test -n "$USE_GCC" -o "$OPSYS" = MORE
  411. then
  412.     F68881="-m68881"
  413. fi
  414.  
  415. case $MACHINE in
  416.     RS6000)
  417.     MODULE="$MODULEKIND"RS6000"$DEBUG" 
  418.     MO=${MO-"../mo.rs6000"}
  419.         ;;
  420.     M68)
  421.     case $OPSYS in
  422.     SUNOS|MACH)
  423.         DEFS="$DEFS -DBSD -Dsun3"
  424.         CFL="-n $F68881"
  425.     ;;
  426.     MORE)
  427.         OPSYS=BSD
  428.         DEFS="$DEFS -DMORE -D__GNUC__"
  429.         F68881="-m68881"            # gcc assumed
  430.         CFL="-z -Bstatic $F68881"
  431.     ;;
  432.     HPUX)
  433.         if [ $HPUX_VERSION = 8 ] 
  434.         then 
  435.              CFL="-Wl,-a,archive"
  436.         fi 
  437.     ;;
  438.     NeXT)
  439.         DEFS="$DEFS -DBSD"
  440.     ;;
  441.     *) ;;
  442.     esac
  443.     MO=${MO-"../mo.m68"}
  444.     MODULE="$MODULEKIND"M68"$DEBUG"
  445.     ;;
  446.     SPARC)
  447.     DEFS="$DEFS -DBSD -Dsun4"
  448.     if [ $OPSYS = SUNOS ]
  449.     then
  450.         CFL="-n"
  451.     fi
  452.     MO=${MO-"../mo.sparc"}
  453.     MODULE="$MODULEKIND"Sparc"$DEBUG"
  454.     ;;
  455.     VAX)
  456.     MO=${MO-"../mo.vax"}
  457.     MODULE="$MODULEKIND"Vax"$DEBUG"
  458.     ;;
  459.     MIPS)
  460.     if test -z "$ENDIAN"
  461.     then
  462.         echo "$CMD determining endianess"
  463.         (cd $RUNTIME; cc -o endian endian.c)
  464.         ENDIAN=`$RUNTIME/endian`
  465.         (cd $RUNTIME; rm -f endian)
  466.     fi
  467.     if test -z "$MO"
  468.     then
  469.         case $ENDIAN in
  470.         Little) MO="../mo.mipsl" ;;
  471.         Big) MO="../mo.mipsb" ;;
  472.          esac
  473.     fi
  474.     case $ENDIAN in
  475.         Little) MODULE="$MODULEKIND"MipsLittle"$DEBUG" ;;
  476.         Big) MODULE="$MODULEKIND"MipsBig"$DEBUG" ;;
  477.     esac
  478.     ;;
  479.     HPPA) if [ $HPUX_VERSION = 8 ] 
  480.         then 
  481.              CFL="-Wl,-a,archive"
  482.         fi 
  483.      MO=${MO-"../mo.hppa"}
  484.     MODULE="$MODULEKIND"Hppa"$DEBUG"
  485.     ;;
  486.     I386)
  487.     MO=${MO-"../mo.i386"}
  488.     MODULE="$MODULEKIND"I386"$DEBUG"
  489.     ;;
  490.     *)
  491.     echo "$CMD must specify machine type"
  492.     exit 1
  493.     ;;
  494. esac
  495.  
  496. if test -n "$TARGET"
  497. then
  498.     case $TARGET in
  499.     rs6k|rs6000)
  500.         TARGET=RS6000
  501.         CSV="~setcalleesaves 3"
  502.     ;;
  503.     m68|M68)
  504.         TARGET=M68
  505.         CSV="~setcalleesaves 0"
  506.     ;;
  507.     sparc|Sparc|SPARC|sun4)
  508.         TARGET=Sparc
  509.         CSV="~setcalleesaves 3"
  510.     ;;
  511.     vax|Vax|VAX)
  512.         TARGET=Vax
  513.         CSV="~setcalleesaves 0"
  514.     ;;
  515.     mips|Mips|MIPS)
  516.         echo "$CMD must specify MIPSL or MIPSB for -target option"
  517.     ;;
  518.     mipsb|MipsB|MIPSB)
  519.         TARGET=Mips
  520.         TARGET_ENDIAN=Big
  521.         CSV="~setcalleesaves 3"
  522.     ;;
  523.     mipsl|MipsL|MIPSL)
  524.         TARGET=Mips
  525.         TARGET_ENDIAN=Little
  526.         CSV="~setcalleesaves 3"
  527.     ;;
  528.         rs6k|rs6000|RS6000)
  529.         TARGET=RS6000
  530.         CSV="~setcalleesaves 3"
  531.     ;;
  532.     i386|386|i486|486)
  533.         TARGET=I386 
  534.             CSV="~setcalleesaves 0"
  535.     ;;
  536.     hppa|Hppa|HPPA|HP-PA|hp-pa)
  537.         TARGET=Hppa
  538.         CSV="~setcalleesaves 3"
  539.     ;;
  540.     *)
  541.         echo "$CMD invalid argument to -target option"
  542.         exit 1
  543.     esac
  544.     MODULE="$MODULEKIND"$TARGET"$TARGET_ENDIAN"
  545. fi
  546.  
  547. if test -n "$IONLY"
  548. then
  549.     if test -n "$TARGET"
  550.     then
  551.     echo "$CMD -target and -ionly options are incompatible"
  552.     exit 1
  553.     fi
  554.     MODULE="IntNull"
  555. fi
  556.  
  557. if test -z "$MOFILES"
  558. then
  559.     MOFILES="$MODULE.mos"
  560. fi
  561.  
  562. DEFS="$DEFS -D$OPSYS"
  563.  
  564.  
  565. if test -n "$PRECLEAN"
  566. then
  567.     echo "$CMD (cd $RUNTIME; make clean)"
  568.     (cd $RUNTIME; make clean)
  569. fi
  570.  
  571. if test ! \( -d "$MO" \)
  572. then
  573.     echo "$CMD mo directory $MO not found"
  574.     exit 1
  575. else
  576.     echo "$CMD rm -f mo"
  577.     rm -f mo
  578.     if test \( -d mo \) -o \( -f mo \)
  579.     then
  580.     echo "$CMD unable to remove ./mo"
  581.     exit 1
  582.     fi
  583.     echo "$CMD ln -s $MO mo"
  584.     ln -s $MO mo
  585. fi
  586.  
  587. if test -n "$MKRUN"
  588. then
  589.     echo "$CMD (cd $RUNTIME; rm -f run allmo.o allmo.s)"
  590.     (cd $RUNTIME; rm -f run allmo.o allmo.s)
  591.  
  592.     if test -n "$USE_GCC"
  593.     then
  594.     GCC=${GCC-"gcc"}
  595.     CCARG="'CC=$GCC -traditional'"
  596.     else
  597.     CCARG=""
  598.     fi
  599.  
  600.     if test -n "$SHARE"
  601.     then
  602.     ARG="MACHINE=$MACHINE $CCARG 'CFL=$CFL' 'LDFLAGS=$LDFLAGS' 'LIBS=$LIBS' 'DEFS=$DEFS -DRUNTIME=\\\"$RUNTIME\\\"' linkdata"
  603.     echo "$CMD (cd $RUNTIME; make $ARG)"
  604.     (cd $RUNTIME; eval make $ARG)
  605.     if test "$?" -ne "0"; then
  606.         exit 1
  607.     fi
  608.  
  609.     if test "$MACHINE" = "M68"; then
  610.       # remove the (unnecessary) Math structure
  611.         echo "(cd $RUNTIME; grep -v mo/Math.mo $MOFILES > Tmp.mos)"
  612.         (cd $RUNTIME; grep -v mo/Math.mo $MOFILES > Tmp.mos)
  613.         MOFILES=Tmp.mos
  614.     fi
  615.  
  616.     echo "$CMD $RUNTIME/linkdata [$RUNTIME/$MOFILES]"
  617.     $RUNTIME/linkdata `cat $RUNTIME/$MOFILES`
  618.     if test "$?" -ne "0"; then
  619.         exit 1
  620.     fi
  621.  
  622.     rm -f $RUNTIME/Tmp.mos
  623.     fi
  624.  
  625.     BASEARG="$CCARG MACHINE=$MACHINE 'DEFS=$DEFS'"
  626.     if test "$MACHINE" = MIPS
  627.     then
  628.     ARG="$BASEARG 'CPP=/lib/cpp -P' 'CFL=$CFL' 'LDFLAGS=$LDFLAGS' 'AS=$AS' 'LIBS=$LIBS'"
  629.     else
  630.     ARG="$BASEARG CPP=/lib/cpp 'CFL=$CFL' 'LDFLAGS=$LDFLAGS' 'AS=$AS' 'LIBS=$LIBS'"
  631.     fi
  632.  
  633.     if test "$OPSYS" = HPUX -a "$MACHINE" = M68
  634.     then
  635.       # convert sun-style assembler code to HP syntax
  636.     echo "$CMD (cd $RUNTIME; ...)"
  637.     ( cd $RUNTIME; \
  638.       unset PWD;
  639.       if test -z "$CALLEESAVE"; then CALLEESAVE="0"; fi;
  640.       echo "$CMD   /lib/cpp -DCALLEESAVE=$CALLEESAVE -DM68 -DHPUX -DASM M68.prim.s > prim.s"; \
  641.       /lib/cpp -DCALLEESAVE=$CALLEESAVE -DM68 -DHPUX -DASM M68.prim.s > prim.s; \
  642.       echo "$CMD   emacs -batch -l sun2hp.el prim.s prim.s"; \
  643.       emacs -batch -l sun2hp.el prim.s prim.s ; \
  644.       echo "$CMD   as -o prim.o prim.s"; \
  645.       as -o prim.o prim.s )
  646.     fi
  647.  
  648.     echo "$CMD (cd $RUNTIME; make $ARG)"
  649.     (cd $RUNTIME; eval make $ARG)
  650.     if test "$?" -ne "0"; then
  651.     exit 1
  652.     fi
  653. fi
  654.  
  655. if test -n "$NOBOOT"
  656. then
  657.     exit 0
  658. fi
  659.  
  660. RUNTIMESTAMP=`cat runtime/run | runtime/crc`
  661. COMMAND=$COMMAND" System.runtimeStamp := \"$RUNTIMESTAMP\";"
  662.  
  663. if test "$MODULEKIND" = Int
  664. then
  665.     STARTUP='('$COMMAND' exportML "'$IMAGE'"; output(std_out,System.version); output(std_out,(chr 10)); output(std_out, '$MESSAGE'));'
  666.     echo "$CMD echo $STARTUP | $RUNTIME/run -m $SOFTLIMIT -r $RATIO -h $HEAP $MODULE"
  667.     $RUNTIME/run -m $SOFTLIMIT -r $RATIO -h $HEAP $MODULE <<XXX
  668.     $STARTUP
  669. XXX
  670. else
  671.     echo "$CMD $RUNTIME/run -m $SOFTLIMIT -r $RATIO -h $HEAP $MODULE"
  672.     $RUNTIME/run -m $SOFTLIMIT -r $RATIO -h $HEAP $MODULE <<XXX
  673. $CSV
  674. >$IMAGE
  675. XXX
  676. fi
  677.  
  678. if test -n "$POSTCLEAN"
  679. then
  680.     echo "$CMD rm -f mo"
  681.     rm -f mo
  682.     (cd $RUNTIME; eval make clean; rm -f mo)
  683. fi
  684.  
  685. exit 0
  686.